package com.kaizeli.website.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 验收成员JPA实体类
 */
@Data
@Entity
@Table(name = "acceptance_member",
       indexes = {
           @Index(name = "idx_acceptance_id", columnList = "acceptanceId"),
           @Index(name = "idx_employee_id", columnList = "employeeId"),
           @Index(name = "idx_status", columnList = "status")
       })
public class AcceptanceMemberEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @Comment("主键ID")
    private Long id;
    
    @Column(name = "acceptance_id", nullable = false)
    @Comment("验收单ID")
    private Long acceptanceId;
    
    @Column(name = "employee_id")
    @Comment("员工ID（可为空，当只配置了岗位时）")
    private Long employeeId;
    
    @Column(name = "employee_name", length = 100)
    @Comment("员工姓名（冗余字段）")
    private String employeeName;
    
    @Column(name = "employee_code", length = 50)
    @Comment("员工编号（冗余字段）")
    private String employeeCode;
    
    @Column(name = "job_title", length = 100)
    @Comment("岗位名称")
    private String jobTitle;
    
    @Column(name = "unit_price", precision = 10, scale = 2)
    @Comment("单价")
    private BigDecimal unitPrice;
    
    @Column(name = "price_type", length = 20)
    @Comment("单价类型（hour-时，day-天，month-月）")
    private String priceType = "hour";
    
    @Column(name = "estimated_hours", precision = 10, scale = 2)
    @Comment("预计工时")
    private BigDecimal estimatedHours;
    
    @Column(name = "actual_hours", precision = 10, scale = 2)
    @Comment("实际工时")
    private BigDecimal actualHours;
    
    @Column(name = "settlement_amount", precision = 15, scale = 2)
    @Comment("结算金额（计算字段）")
    private BigDecimal settlementAmount;
    
    @Column(name = "status", length = 50)
    @Comment("验收状态（待验收、已验收、验收失败）")
    private String status = "待验收";
    
    @Column(name = "attachment_url", length = 500)
    @Comment("验收附件URL")
    private String attachmentUrl;
    
    @Column(name = "remark", columnDefinition = "TEXT")
    @Comment("备注")
    private String remark;
    
    @Column(name = "create_time", nullable = false, updatable = false)
    @Comment("创建时间")
    private LocalDateTime createTime;
    
    @Column(name = "update_time", nullable = false)
    @Comment("更新时间")
    private LocalDateTime updateTime;
    
    @PrePersist
    protected void onCreate() {
        createTime = LocalDateTime.now();
        updateTime = LocalDateTime.now();
    }
    
    @PreUpdate
    protected void onUpdate() {
        updateTime = LocalDateTime.now();
    }
}
